<template>
  <div class="screen">
    <div class="header">智慧城市平台</div>
    <div class="main">
      <div class="left">
        <div class="city-event" v-for="(val, key) in dataInfo" :key="key">
          <h3>{{ val.name }}</h3>
          <div class="inner">
            <img src="@/assets/images/kl.png" />
            <span>
              <b-count-to
                :startVal="0"
                :endVal="val.number"
                :decimals="2"
                ref="countTo"
              ></b-count-to>
              ({{ val.unit }})
            </span>
          </div>
          <div class="foot-border"></div>
        </div>
      </div>
      <div class="right">
        <div
          class="city-event"
          v-for="(val, index) in eventList"
          :key="index"
          :class="{ active: currentActive === index }"
          @click="toggleEvent(index)"
        >
          <h3 flex="main:justify cross:center">
            <span flex="cross:center">
              <img v-if="val.name === '电力'" src="/textures/dianli.png" width="30" />
              <img v-else-if="val.name === '火警'" src="/textures/fire.png" width="30" />
              <img v-else src="/textures/jingcha.png" width="30" />
              <span class="pl-5">{{ val.name }}</span>
            </span>

            <span>10:28</span>
          </h3>
          <div class="inner">
            <span>{{ val.type }}</span>
          </div>
          <div class="foot-border"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import eventBus from '@/utils/eventBus'

defineProps({
  dataInfo: Object,
  eventList: Array,
})

const currentActive = ref(0)

function toggleEvent(i) {
  currentActive.value = i

  eventBus.emit('toggleEvent', i)
}

eventBus.on('spriteClick', ({ event, index }) => {
  console.log(event, index)
  currentActive.value = index
})
</script>

<style lang="stylus" scoped>
.screen {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  .header {
    width: 100%;
    height: 112px;
    line-height: 112px;
    background: url('@/assets/images/header9.png') no-repeat;
    background-size: cover;
    background-position: center;
    text-align: center;
    color: #fff;
    font-size: 36px;
  }
  .main {
    display: flex;
    justify-content: space-between;
    .left, .right {
      width: 380px;
      padding: 20px;
    }
    .city-event {
      position: relative;
      margin-bottom: 24px;
      pointer-events: auto;
      cursor: pointer;
      &:before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        border-top: 4px solid rgb(34,133,247);
        border-left: 4px solid rgb(34,133,247);
        width: 20px;
        height: 20px;
      }
      &:after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        border-top: 4px solid rgb(34,133,247);
        border-right: 4px solid rgb(34,133,247);
        width: 20px;
        height: 20px;
      }
      .foot-border {
        position: relative;
        &:before {
          content: '';
          position: absolute;
          left: 0;
          bottom: 0;
          border-bottom: 4px solid rgb(34,133,247);
          border-left: 4px solid rgb(34,133,247);
          width: 20px;
          height: 20px;
        }
        &:after {
          content: '';
          position: absolute;
          right: 0;
          bottom: 0;
          border-bottom: 4px solid rgb(34,133,247);
          border-right: 4px solid rgb(34,133,247);
          width: 20px;
          height: 20px;
        }
      }
      h3 {
        padding: 16px;
        color: #fff;
        font-size: 18px;
      }
      .inner {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px;
        color: #fff;
        font-size: 18px;
        > img {
          width: 30px;
        }
      }
      &.active {
        h3 {
          color: #1089ff;
        }
      }
    }
  }
}
</style>
